package com.jeeplus.modules.act.listener;

import java.util.Map;

import org.activiti.engine.TaskService;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.ExecutionListener;
import org.activiti.engine.delegate.TaskListener;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import com.google.common.collect.Maps;
import com.jeeplus.common.utils.SpringContextHolder;
import com.jeeplus.modules.sys.utils.UserUtils;

import groovy.util.logging.Slf4j;

@Component
@Slf4j
public class ApplyListener implements TaskListener, ExecutionListener {
	private static final long serialVersionUID = -6000293034409953144L;

    @Override
    public void notify(DelegateTask delegateTask) {
    	TaskService taskService = SpringContextHolder.getBean(TaskService.class); 
    	String userId = UserUtils.getUser().getLoginName();
        taskService.setAssignee(delegateTask.getId(),userId);
        Map vars = Maps.newHashMap();
        vars.put("pass", "1");
        taskService.complete(delegateTask.getId(), vars);
    }
 
    @Override
    public void notify(DelegateExecution delegateExecution) {
         System.err.println("=============执行==============");
    }

}
